package com.ruoyi.house_sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.SaleActive;
import com.ruoyi.house_sale.service.ISaleActiveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营销活动Controller
 * 
 * @author ruoyi
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/house_sale/SaleActive")
public class SaleActiveController extends BaseController
{
    @Autowired
    private ISaleActiveService saleActiveService;

    /**
     * 查询营销活动列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:SaleActive:list')")
    @GetMapping("/list")
    public TableDataInfo list(SaleActive saleActive)
    {
        startPage();
        List<SaleActive> list = saleActiveService.selectSaleActiveList(saleActive);
        return getDataTable(list);
    }

    /**
     * 导出营销活动列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:SaleActive:export')")
    @Log(title = "营销活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SaleActive saleActive)
    {
        List<SaleActive> list = saleActiveService.selectSaleActiveList(saleActive);
        ExcelUtil<SaleActive> util = new ExcelUtil<SaleActive>(SaleActive.class);
        util.exportExcel(response, list, "营销活动数据");
    }

    /**
     * 获取营销活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:SaleActive:query')")
    @GetMapping(value = "/{activeid}")
    public AjaxResult getInfo(@PathVariable("activeid") Long activeid)
    {
        return AjaxResult.success(saleActiveService.selectSaleActiveByActiveid(activeid));
    }

    /**
     * 新增营销活动
     */
    @PreAuthorize("@ss.hasPermi('house_sale:SaleActive:add')")
    @Log(title = "营销活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaleActive saleActive)
    {
        return toAjax(saleActiveService.insertSaleActive(saleActive));
    }

    /**
     * 修改营销活动
     */
    @PreAuthorize("@ss.hasPermi('house_sale:SaleActive:edit')")
    @Log(title = "营销活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SaleActive saleActive)
    {
        return toAjax(saleActiveService.updateSaleActive(saleActive));
    }

    /**
     * 删除营销活动
     */
    @PreAuthorize("@ss.hasPermi('house_sale:SaleActive:remove')")
    @Log(title = "营销活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activeids}")
    public AjaxResult remove(@PathVariable Long[] activeids)
    {
        return toAjax(saleActiveService.deleteSaleActiveByActiveids(activeids));
    }
}
